<?php

class IndexAction extends Action
{
    public function __construct()
    {
        parent::__construct();
        session_start();
    }

    function _empty(){
        R('Empty/_empty');
    }

    public function test(){
       /* $model=M('','',C('flashSale'));
        $sql="SELECT b.*,count(1) as persion FROM `f_user` as a inner join f_user_rel as b on a.u_id=b.u_id group by b.u_id,b.site_id having persion>1";
        $result=$model->query($sql);
        foreach ($result as $key=>$val){
            $deletesql="delete from f_user_rel where u_id=".$val['u_id']." and site_id=".$val['site_id']." ";
            $model->execute($deletesql);
            $model->execute( "insert into f_user_rel (u_id,site_id,u_site_status,u_site_task_status) values ('".$val['u_id']."','".$val['site_id']."','".$val['u_site_status']."','".$val['u_site_task_status']."'); ");
        }
        exit;*/

       /* $expresshtml=file_get_contents('http://nikeordertracking.baozun.cn/daemon/sfquery/616945826936');
        $regex4="/<ul class=.*?>.*?<\/ul>/ism";
        if(preg_match_all($regex4, $expresshtml, $matches)){
            $v=implode('',$matches[0]);
        }
        print_r($v);
        exit;*/

        header("Content-type:text/html;charset=utf-8");
      /*  $postData=array('pythontype'=>'getSize','task_url'=>'https://www.adidas.com.cn/item/CP9764','site_id'=>1);
        $url = "http://172.17.0.1/getsize.php";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
        curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        $output =curl_exec($ch);
        curl_close($ch);
        $output=json_decode($output,true);
        $array=$output['data'];
        $ret=$output['status'];
        print_r($array);
        print_r($ret);
        exit;

*/
        $url="http://qianggou.hooioo.com/index.php/";
       //rl="http://sale.com/index.php/";
        $ch = curl_init();
        //任务接口
        // $url="http://qianggou.hooioo.com/index.php/Rpc/planTask";
       //  $post_data = array("type" => 2,"tid"=>4);
        //用户注册数据接口
         $url.="Rpc/taskuser";
        $post_data = array('tid'=> 4,'taskrelid'=>144,'type'=>2);

       // $url="http://sale.com/index.php/Rpc/getRegisterTaskUser";
        //$post_data = array('tid'=> '4','siteid'=>3,'type'=>1);
       // $url="http://sale.com/index.php/Rpc/getRegisterTaskUserBack";
      //  $post_data = array('uid'=> '2829','tid'=>4,'siteid'=>3,'status'=>0,'remarkId'=>22);

       // $url="http://sale.com/index.php/Rpc/createHost";
      //  $post_data = array('task_relid'=> '9','tasktype'=>2);
        //用户注册回调
        // $url="http://sale.com/index.php/Rpc/registerRollback";
        // $post_data = array("uid" => 9,'tid'=>1,'stid'=>2,'type'=>2);
        //任务回调
       // $url="http://sale.com/index.php/Rpc/stoptask";
        //$post_data = array("taskrelid" => 1,'tid'=>1,'type'=>2);
        //获取失效用户
      // $url.="Rpc/checkaccount";
       //$post_data = array('tid'=>4);
        //用户标注为失效
        //$url="http://qianggou.hooioo.com/index.php/Rpc/releaseUser";
        //$post_data = array("uid" => 7545,'stid'=>3);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'User-Agent: FLASHSALE',
            'X-Requested-With: XMLHttpRequest',
        ));
        curl_setopt ( $ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        curl_close($ch);
        print_r($output);
    }

    /**
     *登陆页面
     */
    public function index()
    {
        session_unset();
        session_destroy();
        cookie(null);
        $this->assign("baseConf","");
        $this->display('login');
    }

    /**
     *登陆
     */
    public function doLogin(){
        $pwd = htmlspecialchars($_POST['password']);
        $captcha = is_numeric($_POST['captcha']);
        $username=$_POST['username'];
        if(!filter_var($_POST['username'], FILTER_VALIDATE_EMAIL)){
            $this->error('用户名不正确！');
        }elseif(!$pwd){
            $this->error('请输入密码！');
        }elseif(!$captcha){
            $this->error('请输入有效验证码！');
        }elseif($_SESSION['captcha'] != md5($_POST['captcha'])) {
            $this->error('验证码不正确，请重新输入！');
        }
        $sql="select * from f_member where m_email='".$username."' ";
        $userInfo = M('member','f_',C('flashSale'))->query($sql);
        $userInfo=$userInfo[0];

        $ip=getClientIp();
        if($_SESSION[$ip] < 4) {
            if (empty($userInfo)) {
                $this->error('用户不存在');
            } elseif ($userInfo['m_status'] == 2) {
                $this->error('该用户处于关闭状态，请联系管理员！');//已关闭
            } elseif ($userInfo['m_pwd'] == md5(md5(trim($pwd)) . C('RAND_PASSWORD'))) {
                $sql="select * from f_member as a left join f_member_rel as b on a.m_id=b.m_id left join f_team as c on b.t_id=c.t_id where a.m_id=".$userInfo['m_id']." ";
                $memmberinfo= M('member','f_',C('flashSale'))->query($sql);
                $memmberinfo=$memmberinfo[0];
              //  session('member_info'=>$memmberinfo,);
                $_SESSION['member_info']=$memmberinfo;
                $sql="UPDATE f_member SET m_ip = '".$ip ."' WHERE m_id = ".$userInfo['m_id']." ";
                M('member','f_',C('flashSale'))->execute($sql);
                $_SESSION['ok'] = 1;
                $_SESSION[$ip] = 0;
                $this->redirect('Admin/Index/index');
                // $this->error('该用户处于关闭状态，请联系管理员！');
            } else {
                $_SESSION[$ip] = $_SESSION[$ip] + 1;
                $this->error('密码错误');
            }
            $lifeTime = 1800;
            setcookie(session_name(), session_id(), time() + $lifeTime, "/");
        } else{
            $this->error('密码输错4次');
        }
    }

    /**
     * 生成验证码
     */
    public function verify()
    {
        ob_end_clean();
        import("ORG.Util.Image");
        Image::buildImageVerify(4,1,'png',130,34,'captcha');

        /*3.2写法
         $verify = new \Think\Verify();
         $verify->length   = 4;
         $verify->codeSet = '0123456789';
         $verify->fontttf = '4.ttf';
         $verify->imageW = 130;
         $verify->imageH = 34;
         $verify->fontSize = 16;
         $verify->useCurve = false;
         $verify->useNoise = true;
         $verify->entry();
        */
    }
}